package club.justwill.single.util;

import club.justwill.single.bean.*;
import club.justwill.single.impl.ToolsImpl;
import club.justwill.single.model.*;

import java.util.Date;

/**
 * Created by xiangnan on 15-12-26.
 */
public class ProjectHelper {
    public static Boolean canCreateProjects(CreateProject createProject, JsonResponse obj){
        if (ToolsImpl.isEmpty(createProject.getEndData()) || new Date().after(ToolsImpl.deserializeDate(createProject.getEndData()))) {
            JsonResponseHelper.addError(obj, CoreConstants.PROJECT_ENDTIME_ERROR);
        }
        return !JsonResponseHelper.isHasError(obj);
    }

    public static boolean canAddAgreement(AddAgreement addAgreement, JsonResponse obj) {
        return !JsonResponseHelper.isHasError(obj);
    }

    public static boolean canCreateProjectIntroduce(CreateProjectIntroduce createProjectIntroduce, JsonResponse obj) {
        if (createProjectIntroduce.getType() != ProjectIntroduceType.PROJECT_INTRODUCE
                && createProjectIntroduce.getType() != ProjectIntroduceType.PROJECT_SCHEDULE
                && createProjectIntroduce.getType() != ProjectIntroduceType.TEAM_INTRODUCE) {
            JsonResponseHelper.addError(obj, CoreConstants.PROJECT_INTRODUCE_TYPE_ERROR);
        }else if (createProjectIntroduce.getC_type() != ContentType.TEXT
                && createProjectIntroduce.getC_type() != ContentType.IMAGE
                && createProjectIntroduce.getC_type() != ContentType.AUDIO
                && createProjectIntroduce.getC_type() != ContentType.VEDIO) {
            JsonResponseHelper.addError(obj, CoreConstants.PROJECT_INTRODUCE_CTYPE_ERROR);
        } else if (createProjectIntroduce.getC_type() == ContentType.TEXT
                && ToolsImpl.isEmpty(createProjectIntroduce.getContent())) {
            JsonResponseHelper.addError(obj,CoreConstants.PROJECT_INTRODUCE_TEXT_ERROR);
        }
        return !JsonResponseHelper.isHasError(obj);
    }

    public static boolean canUpdateProjectIntroduce(UpdateProjectIntroduce updateProjectIntroduce, JsonResponse obj) {
        if (updateProjectIntroduce.getType() != ProjectIntroduceType.PROJECT_INTRODUCE
                && updateProjectIntroduce.getType() != ProjectIntroduceType.PROJECT_SCHEDULE
                && updateProjectIntroduce.getType() != ProjectIntroduceType.TEAM_INTRODUCE) {
            JsonResponseHelper.addError(obj, CoreConstants.PROJECT_INTRODUCE_TYPE_ERROR);
        }else if (updateProjectIntroduce.getC_type() != ContentType.TEXT
                && updateProjectIntroduce.getC_type() != ContentType.IMAGE
                && updateProjectIntroduce.getC_type() != ContentType.AUDIO
                && updateProjectIntroduce.getC_type() != ContentType.VEDIO) {
            JsonResponseHelper.addError(obj, CoreConstants.PROJECT_INTRODUCE_CTYPE_ERROR);
        } else if (updateProjectIntroduce.getC_type() == ContentType.TEXT
                && ToolsImpl.isEmpty(updateProjectIntroduce.getContent())) {
            JsonResponseHelper.addError(obj,CoreConstants.PROJECT_INTRODUCE_TEXT_ERROR);
        }
        return !JsonResponseHelper.isHasError(obj);
    }

    public static Boolean canAddSku(AddSKu addSKu, JsonResponse obj) {
        if(addSKu.getUnitPrice() < 0) {
            JsonResponseHelper.addError(obj, CoreConstants.UNIT_PRICE_ERROR);
        }
        return !JsonResponseHelper.isHasError(obj);
    }
}
